package tools 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.Dictionary;
	
	/**
	 * AbstractTool
	 * @author Tom Vian
	 */
	public class AbstractTool extends Sprite 
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		protected var _onSaveLookup:Dictionary = new Dictionary();
		protected var _dataLookup:Dictionary = new Dictionary();
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function AbstractTool() 
		{
			addEventListener(Event.ENTER_FRAME, export);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function export(e:Event):void
		{
			removeEventListener(Event.ENTER_FRAME, export);
		}
		
		public function save(e:MouseEvent):void
		{
			var text:TextField = e.target as TextField;
			
			handleSave(text, _dataLookup[text]);
			
			var file:File = new File;
			
			file.addEventListener(Event.SELECT, _onSaveLookup[text]);
			//file.browseForDirectory("Select a location");
			file.browseForOpen("Select a location");
		}
		
		public function addButton(message:String, x:Number, y:Number, onClick:Function, onSelectFile:Function = null, extraData:Object = null):void
		{
			var text:TextField = new TextField;
			text.selectable = false;
			text.defaultTextFormat = new TextFormat("Arial", 32, 0x454545, true);
			text.text = message;
			text.x = x;
			text.y = y;
			text.width = 800;
			text.height = 50;
			text.addEventListener(MouseEvent.CLICK, onClick);
			addChild(text);
			
			_onSaveLookup[text] = onSelectFile;
			_dataLookup[text] = extraData;
		}
		
		public function handleSave(text:TextField, extraData:Object = null):void
		{
			
		}
	}
}